home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / gfx / show / gs_src_gs.lha / gs5.03 / opdef.h < prev    next >
C/C++ Source or Header  |  1995-12-24  |  5KB  |  139 lines

  1. /* Copyright (C) 1991, 1995 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* opdef.h */
  20. /* Operator definition interface for Ghostscript */
  21.  
  22. /*
  23.  * Operator procedures take the pointer to the top of the o-stack
  24.  * as their argument.  They return 0 for success, a negative code
  25.  * for an error, or a positive code for some uncommon situations (see below).
  26.  */
  27.  
  28. /* Structure for initializing the operator table. */
  29. /*
  30.  * Each operator file declares an array of these, of the following kind:
  31.  
  32. BEGIN_OP_DEFS(my_defs) {
  33.     {"1name", zname},
  34.         ...
  35. END_OP_DEFS(iproc) }
  36.  
  37.  * where iproc is an initialization procedure for the file, or 0.
  38.  * This definition always appears at the END of the file,
  39.  * to avoid the need for forward declarations for all the
  40.  * operator procedures.
  41.  *
  42.  * Operators may be stored in dictionaries other than systemdict.
  43.  * We support this with op_def entries of a special form:
  44.  
  45.     op_def_begin_dict("dictname"),
  46.  
  47.  */
  48. typedef struct {
  49.     const char _ds *oname;
  50.     op_proc_p proc;
  51. } op_def;
  52. typedef const op_def *op_def_ptr;
  53. #define op_def_begin_dict(dname) {dname, 0}
  54. #define op_def_begin_filter() op_def_begin_dict("filterdict")
  55. #define op_def_begin_level2() op_def_begin_dict("level2dict")
  56. #define op_def_is_begin_dict(def) ((def)->proc == 0)
  57. #define op_def_end(iproc) {(char _ds *)0, (op_proc_p)iproc}
  58.  
  59. /*
  60.  * We need to define each op_defs table as a procedure that returns
  61.  * the actual table, because of cross-segment linking restrictions
  62.  * in the Borland C compiler for MS Windows.
  63.  */
  64.  
  65. #define BEGIN_OP_DEFS(xx_op_defs)\
  66. const op_def *xx_op_defs(P0())\
  67. {    static const far_data op_def op_defs_[] =
  68.  
  69. #define END_OP_DEFS(iproc)\
  70.         op_def_end(iproc)\
  71.     };\
  72.     return op_defs_;
  73.  
  74. /*
  75.  * Internal operators whose names begin with %, such as continuation
  76.  * operators, do not appear in systemdict.  Ghostscript assumes
  77.  * that these operators cannot appear anywhere (in executable form)
  78.  * except on the e-stack; to maintain this invariant, the execstack
  79.  * operator converts them to literal form, and cvx refuses to convert
  80.  * them back.  As a result of this invariant, they do not need to
  81.  * push themselves back on the e-stack when executed, since the only
  82.  * place they could have come from was the e-stack.
  83.  */
  84. #define op_def_is_internal(def) ((def)->oname[1] == '%')
  85.  
  86. /*
  87.  * All operators are catalogued in a table; this is necessary because
  88.  * they must have a short packed representation for the sake of 'bind'.
  89.  * The `size' of an operator is normally its index in this table;
  90.  * however, internal operators have a `size' of 0, and their true index
  91.  * must be found by searching the table for their procedure address.
  92.  */
  93. ushort op_find_index(P1(const ref *));
  94. #define op_index(opref)\
  95.   (r_size(opref) == 0 ? op_find_index(opref) : r_size(opref))
  96. /*
  97.  * There are actually two kinds of operators: the real ones (t_operator),
  98.  * and ones defined by procedures (t_oparray).  The catalog for t_operators
  99.  * is op_def_table, and their index is in the range [1..op_def_count-1].
  100.  */
  101. #define op_index_is_operator(index) ((index) < op_def_count)
  102. /*
  103.  * Because of a bug in Sun's SC1.0 compiler,
  104.  * we have to spell out the typedef for op_def_ptr here:
  105.  */
  106. extern const op_def **op_def_table;
  107. extern uint op_def_count;
  108. #define op_num_args(opref) (op_def_table[op_index(opref)]->oname[0] - '0')
  109. #define op_index_proc(index) (op_def_table[index]->proc)
  110. /*
  111.  * There are two catalogs for t_oparrays, one global and one local.
  112.  * Operator indices for the global table are in the range
  113.  *    [op_def_count..op_def_count+op_array_global.count-1]
  114.  * Operator indices for the local table are in the range
  115.  *    [op_def_count+r_size(&op_array_global.table)..
  116.  *      op_def_count+r_size(&op_array_global.table)+op_array_local.count-1]
  117.  */
  118. typedef struct op_array_table_s {
  119.     ref table;            /* t_array */
  120.     ushort *nx_table;        /* name indices */
  121.     uint count;            /* # of occupied entries */
  122.     uint base_index;        /* operator index of first entry */
  123.     uint attrs;            /* ref attrs of ops in this table */
  124.     ref *root_p;            /* self-pointer for GC root */
  125. } op_array_table;
  126. extern op_array_table
  127.   op_array_table_global,
  128.   op_array_table_local;
  129. #define op_index_op_array_table(index)\
  130.   ((index) < op_array_table_local.base_index ?\
  131.    &op_array_table_global : &op_array_table_local)
  132.  
  133. /*
  134.  * Convert an operator index to an operator or oparray ref.
  135.  * This is only used for debugging and for 'get' from packed arrays,
  136.  * so it doesn't have to be very fast.
  137.  */
  138. void op_index_ref(P2(uint, ref *));
  139.